package com.xc.stock.application.assembler;

import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import com.xc.stock.constant.AccountType;
import com.xc.stock.domain.basic.entity.Account;
import com.xc.stock.dto.AccountDTO;
import com.xc.stock.utils.Beans;
import com.xc.stock.utils.SpringUtils;

/**
 * AccountAssembler
 *
 * @author xlfd
 * @email xlfd@gmail.com
 * @created 2022/03/25
 */
@Component
@Lazy
public class AccountAssembler {
	public AccountDTO toDTO(Account e) {
		AccountDTO dto = Beans.mapper(e, AccountDTO.class);
		if (dto == null)
			return dto;
		fill(e, dto);
		return dto;
	}

	protected void fill(Account e, AccountDTO dto) {
		if (dto == null)
			return;
		dto.setAccountTypeText(AccountType.remark(e.getAccountType()));
		return;
	}

	public static AccountAssembler of() {
		return SpringUtils.getBean(AccountAssembler.class);
	}
}
